package com.widget.toolbar;

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.RelativeLayout;

import com.mylove.judas.yaya.R;


/**
 * Created by Administrator on 2017/5/12 0012.
 */
public class ToolBarX {

    private Toolbar mToolbar;
    private RelativeLayout rl_custom;
    private ActionBar mActionbar;
    private AppCompatActivity mActivity;

    public ToolBarX(AppCompatActivity mActivity, Toolbar mToolbar) {
        this.mActivity = mActivity;
        this.mToolbar = mToolbar;
        rl_custom = (RelativeLayout) mToolbar.findViewById(R.id.rl_custom);

        mActivity.setSupportActionBar(mToolbar);
        mActionbar = mActivity.getSupportActionBar();

    }

    /**
     * 添加自定义标题栏view
     * @param view
     * @return
     */
    public ToolBarX setCustomView(View view){
        rl_custom.removeAllViews();
        rl_custom.addView(view);
        return this;
    }

    /**
     * 设置标题
     * @param title
     * @return
     */
    public ToolBarX setTitle(String title){
        mActionbar.setTitle(title);
        return this;
    }

    /**
     * 设置标题
     * @param resId
     * @return
     */
    public ToolBarX setTitle(int resId){
        mActionbar.setTitle(resId);
        return this;
    }

    /**
     * 设置副标题
     * @param subTitle
     * @return
     */
    public ToolBarX setSubtitle(String subTitle){
        mActionbar.setSubtitle(subTitle);
        return this;
    }

    /**
     * 设置副标题
     * @param resId
     * @return
     */
    public ToolBarX setSubtitle(int resId){
        mActionbar.setSubtitle(resId);
        return this;
    }

    public ToolBarX setNavigationIcon(int resId){
        mToolbar.setNavigationIcon(resId);
        return this;
    }

    /**
     * 是否显示返回按钮...
     * @param showHomeAsUp
     * @return
     */
    public ToolBarX setDisplayHomeAsUpEnabled(boolean showHomeAsUp){
        mActionbar.setDisplayHomeAsUpEnabled(showHomeAsUp);
        return this;
    }

    public ToolBarX setDisplayShowTitleEnabled(boolean showTitle){
        mActionbar.setDisplayShowTitleEnabled(showTitle);
        return this;
    }

    public ToolBarX setNavigationOnClickListener(View.OnClickListener listener){
        mToolbar.setNavigationOnClickListener(listener);
        return this;
    }

    public ToolBarX inflateMenu(int resId){
        mToolbar.inflateMenu(resId);
        return this;
    }


    /**
     * 获取Toolbar
     * @return
     */
    public Toolbar getToolbar(){
        return mToolbar;
    }

    /**
     * 隐藏Toolbar
     * @return
     */
    public ToolBarX hide(){
        mActionbar.hide();
        return this;
    }

}
